package com.shr.code_interview;

public class Solution_24 {
    public static ListNode ReverseList(ListNode head) {
        if(head == null)
            return null ;
        ListNode hHead = new ListNode(0) ;
        hHead.next = head ;
        ListNode pNode = head.next;
        head.next = null ;
        while(pNode!=null){
            ListNode tNode = pNode.next ;
            pNode.next = hHead.next;
            hHead.next = pNode;
            pNode = tNode;
        }
        return hHead.next ;
    }
    public static void main(String[] args) {
		ListNode head = new ListNode(0) ;
		ListNode node = head;
    	for(int i = 1; i<5; i++){
    		node.next = new ListNode(i);
    		node = node.next ;
		}
    	ListNode listNode = ReverseList(head);
    	while(listNode!=null){
    		System.out.print(listNode.val+" ");
    		listNode = listNode.next ;
    	}
    	
	}
}
